package logic

import (
	"context"
	"market/model/redis"
	"strconv"

	"market/marketrpc/internal/svc"
	"market/marketrpc/marketrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PorductLikeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPorductLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PorductLikeListLogic {
	return &PorductLikeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PorductLikeListLogic) PorductLikeList(in *marketrpc.PorductLikeListRequest) (*marketrpc.PorductLikeListResponse, error) {
	// todo: add your logic here and delete this line

	rev := redis.Client.ZRevRangeWithScores("productilkel", 0, 9)
	var likes []*marketrpc.PorductLikeList
	for _, z := range rev.Val() {

		list := &marketrpc.PorductLikeList{
			Like: z.Member.(string),
			Name: strconv.Itoa(int(z.Score)),
		}
		likes = append(likes, list)
	}

	return &marketrpc.PorductLikeListResponse{List: likes}, nil
}
